package com.itheima.smspringboot.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.smspringboot.common.Result;
import com.itheima.smspringboot.entity.Teacher;
import com.itheima.smspringboot.service.TeacherService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Resource
    private TeacherService teacherService;


    @PostMapping("/add")
    public Result add(@RequestBody Teacher teacher) {
        teacherService.add(teacher);
        return Result.success();
    }
    //
    @PutMapping("/update")
    public Result update(@RequestBody Teacher teacher) {
        teacherService.updateById(teacher);
        return Result.success();
    }
    //
    @DeleteMapping("/delete/{stuId}")
    public Result delete(@PathVariable Integer stuId) {
        teacherService.deleteById(stuId);
        return Result.success();

    }
    //
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Teacher> teacherList) {
        teacherService.deleteBatch(teacherList);
        return Result.success();

    }



    @GetMapping("/selectAll")
    public Result selectAll(Teacher teacher) {
        List<Teacher> teacherList = teacherService.selectAll(teacher);
        return Result.success(teacherList);
    }


    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             Teacher teacher){
        PageInfo pageInfo = teacherService.selectPage(pageNum, pageSize,teacher);
        return Result.success(pageInfo);

    }
}
